const ONE_DAY = 24 * 60 * 60 * 1000

function format_ymd(date) {
  const yyyy = date.getFullYear()
  const mm = (date.getMonth() + 1).toString().padStart(2, '0')
  const dd = date.getDate().toString().padStart(2, '0')
  return `${yyyy}-${mm}-${dd}`
}

function last_month_last_date(date) {
  const date1 = new Date(new Date(date).valueOf() - ONE_DAY)
  return format_ymd(date1)
}

function next_month_first_date(date) {
  const dt = new Date(date)
  dt.setDate(1)
  const dt2 = new Date(dt.valueOf() + 31 * ONE_DAY)
  dt2.setDate(1)
  return format_ymd(dt2)
}

export const date_helper = {
  last_month_last_date,
  next_month_first_date
}

export default {}
